#include <iostream>
#include <string>
#include <unordered_map>
#include <sstream>

bool is_prime(int number) {
    if (number <= 1) return false;
    for (int i = 2; i * i <= number; i++) {
        if (number % i == 0) return false;
    }
    return true;
}

int next_prime(int number) {
    while (true) {
        number++;
        if (is_prime(number)) {
            return number;
        }
    }
}

int main() {
    std::unordered_map<std::string, std::string> num_word{{"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"}, {"four", "4"}, {"five", "5"}, {"six", "6"}, {"seven", "7"}, {"eight", "8"}, {"nine", "9"}};
    std::string input, num_str = "", word;
    std::getline(std::cin, input);
    std::istringstream iss(input);
    while (iss >> word) {
        if (num_word.find(word) == num_word.end()) {
            std::cout << "Wrong input" << std::endl;
            return 0;
        }
        num_str += num_word[word];
    }
    if (num_str.length() == 3) {
        int number = std::stoi(num_str);
        int closest_prime = is_prime(number) ? number : next_prime(number);
        while (true) {
            --number;
            if (number > 1 && is_prime(number)) {
                std::cout << number << std::endl;
                break;
            }
            if (is_prime(closest_prime)) {
                std::cout << closest_prime << std::endl;
                break;
            }
            ++closest_prime;
        }
    } else {
        std::cout << "Wrong input" << std::endl;
    }
    return 0;
}
